package adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.xingzai.myapplication.R;

import java.util.ArrayList;

public class MyAdapter extends BaseAdapter {

    private ArrayList<Group> groups;
    private Context context;

    public MyAdapter(ArrayList<Group> persons, Context context) {
        super();
        this.groups = persons;
        this.context = context;
    }

    @Override
    public int getCount() {
        return groups.size();
    }

    @Override
    public Object getItem(int position) {
        return groups.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.item_03, null);
        TextView name = (TextView) convertView.findViewById(R.id.name);
        TextView num = (TextView) convertView.findViewById(R.id.num);
        LinearLayout layout = (LinearLayout) convertView
                .findViewById(R.id.linearlayout);
        if (position % 2 == 0) {
            name.setTextColor(Color.WHITE);
            num.setTextColor(Color.YELLOW);
            layout.setBackgroundColor(Color.BLACK);
        }
        Group p = groups.get(position);
        name.setText(p.getName());
        num.setText(p.getNum());
        return convertView;
    }
}
